package com.googlecode.stockhamster.client.console;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import com.googlecode.stockhamster.Constant;
import com.googlecode.stockhamster.company.ICompany;
import com.googlecode.stockhamster.utils.XFireStub;

public class CompanyInitializer {

	/**
	 * @param args
	 * @throws IOException
	 * @throws NumberFormatException
	 */
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		ICompany company = new XFireStub<ICompany>(Constant.companyUrl,
				ICompany.class).getStub();
		BufferedReader br = new BufferedReader(new FileReader(
				Constant.companyListCSV));
		String line;

		while ((line = br.readLine()) != null) {
			String items[] = line.split(",");
			if (items.length == 5) {
				Boolean ret = company.addCompany(Constant.companyAdminCode,
						items[0], items[1], Long.valueOf(items[2]), Integer
								.valueOf(items[3]), Double.valueOf(items[4]));
				System.out.println("Add company " + items[0] + ": " + ret);
			}
		}
	}

}
